using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using BoOnce.GameLogic;
using FarseerGames.FarseerPhysics;
using BoOnce.Xml;
using FarseerGames.FarseerPhysics.Dynamics;
using FarseerGames.FarseerPhysics.Collisions;

namespace BoOnce.Physic
{
    class PhysicComponent_MonoSimulator : IPhysicComponent
    {
        #region Attributes
        PhysicsSimulator[] _ArrayOfSimulator;
        PhysicsSimulator _Simulator;
        PhysicComponentConfigXml _Config;
        #endregion

        #region Constructor
        public PhysicComponent_MonoSimulator(Game game, PhysicComponentConfigXml config)
        {
            _Config = config;
            _Simulator = new PhysicsSimulator(_Config.Gravity);
            _ArrayOfSimulator = new PhysicsSimulator[1];
            _ArrayOfSimulator[0] = _Simulator;
        }
        #endregion

        #region IPhysicComponent
        public void Initialize()
        {
        }

        public void Remove(Body body, Geom geom)
        {
            _Simulator.Remove(body);
            _Simulator.Remove(geom);
        }

        public Ground AddPhysicalEntity(Body body,Geom geom, float height)
        {
            _Simulator.Add(body);
            _Simulator.Add(geom);
            return null;
        }

        public Ground NotifyMove(Vector2 newPos, Ground currentGround, Body body,Geom geom, float height, ref float accumulator)
        {
            body.Position = newPos;
            return null;
        }

        public PhysicsSimulator[] Simulators
        {
            get { return _ArrayOfSimulator; }
        }
        #endregion

        public void Update(GameTime gameTime)
        {
            _Simulator.Update(gameTime.ElapsedGameTime.Milliseconds * .001f);
        }
    }
}
